//键盘选择
export const togglekeyup = (e) => {
  // if (e.keyCode === 9)  state.visible = false
  // 当表格未获取到元素值或者表格无数据时，返回
  if (!tableRef.value || state.Data.length === 0) return

  state.enterFlag = true
  const contentHeight = tableRef.value._.refs.bodyWrapper.offsetHeight // 表格内部的视图高度

  // 下键 ArrowDown
  if (e.keyCode == 40) {
    state.index += 1
    if (state.index === state.Data.length) {
      state.index = 0
      state.pageIndex = 1
      if (tableRef.value) tableRef.value.setScrollTop(0) // 滚动到 state.index 行的位置
    }

    if (32 * (state.index + 1) >= contentHeight * state.pageIndex) {
      state.pageIndex++
      if (tableRef.value) tableRef.value.setScrollTop(32 * state.index) // 滚动到 state.index 行的位置
    }
  }
  // 上键 ArrowUp
  if (e.keyCode == 38) {
    // 上键 ArrowUp e.keyCode == 38

    if (state.index > 0) state.index--
    if (32 * (state.index + 1) <= contentHeight * (state.pageIndex - 1)) {
      state.pageIndex--
      if (tableRef.value) tableRef.value.setScrollTop(32 * (state.index + 1) - contentHeight) // 滚动到 state.index 行的位置
    }
  }

  if (e.keyCode == 13) {
    // 点击enter，选中数据，关闭弹窗
    if (state.index !== -1) {
      const currentRow = state.Data[state.index]

      rowdblclick(currentRow) // 设置默认值
      input.value.blur()

      nextTick(() => {
        state.visible = false
      })
    }
  }
}
